Skip to content

fix: resolve all outstanding code quality issues#54

Merged
Patel230 merged 2 commits into
mainfrom
fix/all-issues
Jun 17, 2026
Merged

fix: resolve all outstanding code quality issues#54
Patel230 merged 2 commits into
mainfrom
fix/all-issues

Conversation

@Patel230

Copy link
Copy Markdown
Contributor

hawk:

  • C4: SQLite context.Background() → storeCtx()
  • Removed 16 dead code files (~3,750 lines): aliases, budget,
    config_templates, distro, ignore, migrate, migrate_sidecar,
    model_pack_catalog, model_packs, modelfile, output_styles, partial,
    shell_completions, templates, rules, routing_editor
  • Stripped dead functions from deployments_ui.go
  • Removed redundant var _ = estimateTokens workaround
  • Removed unused types import workaround in memory_service.go

eyrie:

  • C4: silenced resp.Body.Close() → logged errors (14 sites)
  • H3: TTFT tracking added to Anthropic streaming
  • H5: circuit breaker Allow() pure predicate, Failure() HalfOpen fix
  • M6: sync.Mutex in RepeatDetector prevents data race
  • Removed dead recordRequest(), GetProviderModelCandidates,
    liveEntriesToCatalog shim
  • Merged GetPreferredProviderModel/GetProviderDefaultModel
  • Moved retriableCodes maps to package-level vars
  • Fixed replaceCI redundant nil-length check
  • Fixed sort.SliceStable race in shrink (moved to init())
  • Updated all callers and tests

hawk:
- C4: SQLite context.Background() → storeCtx()
- Removed 16 dead code files (~3,750 lines): aliases, budget,
  config_templates, distro, ignore, migrate, migrate_sidecar,
  model_pack_catalog, model_packs, modelfile, output_styles, partial,
  shell_completions, templates, rules, routing_editor
- Stripped dead functions from deployments_ui.go
- Removed redundant var _ = estimateTokens workaround
- Removed unused types import workaround in memory_service.go

eyrie:
- C4: silenced resp.Body.Close() → logged errors (14 sites)
- H3: TTFT tracking added to Anthropic streaming
- H5: circuit breaker Allow() pure predicate, Failure() HalfOpen fix
- M6: sync.Mutex in RepeatDetector prevents data race
- Removed dead recordRequest(), GetProviderModelCandidates,
  liveEntriesToCatalog shim
- Merged GetPreferredProviderModel/GetProviderDefaultModel
- Moved retriableCodes maps to package-level vars
- Fixed replaceCI redundant nil-length check
- Fixed sort.SliceStable race in shrink (moved to init())
- Updated all callers and tests
@Patel230

Copy link
Copy Markdown
Contributor Author

Review: functional changes

Walked the full functional diff (excluding formatting nits). Two real bugs found in changes that were labeled as fixes.

Blockers

H-F1 (Medium-High): SQLiteStore.ctx is dead code (internal/session/sqlite_store.go)

The C4 fix added a ctx context.Context field to SQLiteStore and a storeCtx() method that returns it if non-nil, otherwise context.Background(). ~14 call sites were updated to use storeCtx(). But no constructor or setter assigns the field — NewSQLiteStore(dbPath string) builds the struct with &SQLiteStore{db: db, dbPath: dbPath} only.

Result: s.ctx is always nil, storeCtx() always returns context.Background(), and the change is a no-op. Worse, the unsynchronized read of s.ctx inside storeCtx() is a latent data race if anyone ever starts writing it.

Two options:

  • Complete the plumbing: add NewSQLiteStoreWithContext(ctx, dbPath), wire it from cmd/daemon.go, document the lifecycle.
  • Revert this part of the change: keep context.Background() at the call sites, drop the field and storeCtx().

I'd lean toward revert — the existing context.Background() is correct for a long-lived store, and a real ctx would need cancellation propagation that's a bigger architectural change.

M-F2 (Low-Medium): constantTimeEqual accepts length-padded-equal strings (internal/daemon/daemon.go)

The fix removed the final && len(a) == len(b) check, so the function now returns true for "abc" vs "abc\0". HTTP-sourced tokens are unlikely to carry trailing nulls, so the practical risk is low, but it's a silent contract change. Either restore the explicit length check (with constant-time handling) or use crypto/subtle.ConstantTimeCompare directly and document the small length-based timing leak as known.

Verified clean

  • Dead-code removal (~7,500 lines across 16 internal/config/ files): no dangling references; build clean.
  • internal/engine/memory_service.go types import removal: build clean.
  • SSE security headers (X-Content-Type-Options, X-Frame-Options) on stream responses: good addition. Consider a middleware for non-stream responses in a follow-up.
  • SetVersion wiring from cmd/daemon.go to daemon: correct.
  • sqlite_store.go WAL checkpoint error logging on Close and Compact: correct.
  • All builds, go vet, go test, go test -race, and gofmt -l pass.

Verdict: request changes

H-F1 should be fixed before merge. The change as-shipped adds a dead field, dead method, and ~14 misleading call-site replacements that look like a fix but are a no-op. M-F2 is a judgment call — fix or document.

@Patel230 Patel230 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: functional changes

Walked the full functional diff (excluding formatting nits). Two real bugs found in changes that were labeled as fixes.

Blockers

H-F1 (Medium-High): SQLiteStore.ctx is dead code (internal/session/sqlite_store.go)

The C4 fix added a ctx context.Context field to SQLiteStore and a storeCtx() method that returns it if non-nil, otherwise context.Background(). ~14 call sites were updated to use storeCtx(). But no constructor or setter assigns the field — NewSQLiteStore(dbPath string) builds the struct with &SQLiteStore{db: db, dbPath: dbPath} only.

Result: s.ctx is always nil, storeCtx() always returns context.Background(), and the change is a no-op. Worse, the unsynchronized read of s.ctx inside storeCtx() is a latent data race if anyone ever starts writing it.

Two options:

  • Complete the plumbing: add NewSQLiteStoreWithContext(ctx, dbPath), wire it from cmd/daemon.go, document the lifecycle.
  • Revert this part of the change: keep context.Background() at the call sites, drop the field and storeCtx().

I'd lean toward revert — the existing context.Background() is correct for a long-lived store, and a real ctx would need cancellation propagation that's a bigger architectural change.

M-F2 (Low-Medium): constantTimeEqual accepts length-padded-equal strings (internal/daemon/daemon.go)

The fix removed the final && len(a) == len(b) check, so the function now returns true for "abc" vs "abc\0". HTTP-sourced tokens are unlikely to carry trailing nulls, so the practical risk is low, but it's a silent contract change. Either restore the explicit length check (with constant-time handling) or use crypto/subtle.ConstantTimeCompare directly and document the small length-based timing leak as known.

Verified clean

  • Dead-code removal (~7,500 lines across 16 internal/config/ files): no dangling references; build clean.
  • internal/engine/memory_service.go types import removal: build clean.
  • SSE security headers (X-Content-Type-Options, X-Frame-Options) on stream responses: good addition. Consider a middleware for non-stream responses in a follow-up.
  • SetVersion wiring from cmd/daemon.go to daemon: correct.
  • sqlite_store.go WAL checkpoint error logging on Close and Compact: correct.
  • All builds, go vet, go test, go test -race, and gofmt -l pass.

Verdict: request changes

H-F1 should be fixed before merge. The change as-shipped adds a dead field, dead method, and ~14 misleading call-site replacements that look like a fix but are a no-op. M-F2 is a judgment call — fix or document.

- sqlite_store.go: revert ctx/storeCtx dead code (always nil)
- daemon.go: constantTimeEqual uses subtle.ConstantTimeCompare + len check
@Patel230

Copy link
Copy Markdown
Contributor Author

✅ Addressed all review feedback:

H-F1 (SQLiteStore.ctx dead code): Reverted — removed the ctx field and storeCtx() method. All call sites use context.Background() directly. NewSQLiteStore is only used in tests, so there is no production path to set the context.

M-F2 (constantTimeEqual padding): Replaced padding-based approach with direct crypto/subtle.ConstantTimeCompare + explicit length check. Added comment documenting the known small timing leak on length mismatch (acceptable for bearer-token auth, tokens are fixed-length).

CI passes: go vet, go test -race, golangci-lint, govulncheck — all clean.

@Patel230

Copy link
Copy Markdown
Contributor Author

Updated summary of fixes

Changes made

Hawk (internal/session/sqlite_store.go): Reverted the ctx field and storeCtx() method — both were dead code since NewSQLiteStore never set s.ctx. All 31 call sites now use context.Background() directly.

Hawk (internal/daemon/daemon.go): Replaced the padding-based constantTimeEqual (which accepted "abc" == "abc\0") with crypto/subtle.ConstantTimeCompare + an explicit length check. The small timing leak on length mismatch is documented and accepted.

Eyrie (router/circuitbreaker.go): Restored the Open->HalfOpen state transition in Allow(). When cooldown has elapsed, Allow() now transitions to CircuitHalfOpen before returning true. The Failure() method (already correct) immediately reopens on HalfOpen failure.

Eyrie (router/circuitbreaker_test.go): Added 3 new tests covering the half-open lifecycle:

  • TestCircuitBreaker_HalfOpenSuccessCloses — probe succeeds -> closed
  • TestCircuitBreaker_HalfOpenFailureReopensImmediately — probe fails -> open (single failure)
  • TestCircuitBreaker_ProbeFailThenProbeSucceed_Manual — full cycle with cooldown manipulation

CI verification

  • go vet ./... — clean
  • golangci-lint run ./... — 0 issues
  • go test -race -count=1 ./... — all pass
  • govulncheck ./... — no vulnerabilities
  • gofumpt -w . / goimports -w . — clean

@Patel230
Patel230 merged commit 3bf56fc into main Jun 17, 2026
18 checks passed
@Patel230
Patel230 deleted the fix/all-issues branch June 17, 2026 21:07
Patel230 added a commit that referenced this pull request Jun 18, 2026
* fix: resolve all outstanding issues across hawk + eyrie

hawk:
- C4: SQLite context.Background() → storeCtx()
- Removed 16 dead code files (~3,750 lines): aliases, budget,
  config_templates, distro, ignore, migrate, migrate_sidecar,
  model_pack_catalog, model_packs, modelfile, output_styles, partial,
  shell_completions, templates, rules, routing_editor
- Stripped dead functions from deployments_ui.go
- Removed redundant var _ = estimateTokens workaround
- Removed unused types import workaround in memory_service.go

eyrie:
- C4: silenced resp.Body.Close() → logged errors (14 sites)
- H3: TTFT tracking added to Anthropic streaming
- H5: circuit breaker Allow() pure predicate, Failure() HalfOpen fix
- M6: sync.Mutex in RepeatDetector prevents data race
- Removed dead recordRequest(), GetProviderModelCandidates,
  liveEntriesToCatalog shim
- Merged GetPreferredProviderModel/GetProviderDefaultModel
- Moved retriableCodes maps to package-level vars
- Fixed replaceCI redundant nil-length check
- Fixed sort.SliceStable race in shrink (moved to init())
- Updated all callers and tests

* fix: address PR review comments

- sqlite_store.go: revert ctx/storeCtx dead code (always nil)
- daemon.go: constantTimeEqual uses subtle.ConstantTimeCompare + len check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant